package com.example.controller;


import com.example.common.Result;
import com.example.entity.PatientVisit;
import com.example.entity.Prescription;
import com.example.service.PrescriptionService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 药单表前端操作接口
 **/
@RestController
@RequestMapping("/prescription")
public class PrescriptionController {

    @Resource
    private PrescriptionService prescriptionService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody Prescription prescription) {
        prescriptionService.add(prescription);
        return Result.success();
    }

    @GetMapping("/addPrescription")
    public Result addPrescription(@RequestParam Integer patientId,@RequestParam Integer doctorId, @RequestParam Integer visitId) {
        Prescription prescription = prescriptionService.addPrescription(patientId, doctorId, visitId);
        return Result.success(prescription);
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        prescriptionService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        prescriptionService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody Prescription prescription) {
        prescriptionService.updateById(prescription);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Prescription prescription = prescriptionService.selectById(id);
        return Result.success(prescription);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(Prescription prescription) {
        List<Prescription> list = prescriptionService.selectAll(prescription);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(Prescription prescription,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Prescription> page = prescriptionService.selectPage(prescription, pageNum, pageSize);
        return Result.success(page);
    }

    @GetMapping("/updateTotalPrice/{prescriptionId}")
    public Result updateTotalPrice(@PathVariable Integer prescriptionId) {
        prescriptionService.updateTotalPrice(prescriptionId);
        return Result.success();
    }

}